/**
 * 
 */
package org.vsg.common.pagination.carrier;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Bill vison
 *
 */
public class HttpRecordLimitCarrier extends AbstractBaseRecordLimitCarrier
		implements WebCarrier {

	
	private final static Logger logger = LoggerFactory.getLogger(HttpRecordLimitCarrier.class);
	
	protected Map parametersMapping = Collections.synchronizedMap(new HashMap());	
	
	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.carrier.WebCarrier#getParameter(java.lang.String)
	 */
	public Object getParameter(String name) {
		// TODO Auto-generated method stub
		Object valueObj = this.parametersMapping.get(name);
		
		if (valueObj != null && valueObj instanceof String[]) {
			String[] values = (String[])valueObj;
			return values[0];
		}
		return valueObj;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.carrier.WebCarrier#getParameterValues(java.lang.String)
	 */
	public String[] getParameterValues(String name) {
		// TODO Auto-generated method stub
		String[] values = (String[])this.parametersMapping.get(name);
		return values;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.carrier.WebCarrier#getParametersMapping()
	 */
	public Map getParametersMapping() {
		// TODO Auto-generated method stub
		return parametersMapping;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.carrier.WebCarrier#setParameter(java.lang.String, java.lang.String)
	 */
	public void setParameter(String name, String value) {
		// TODO Auto-generated method stub
		setParameterObject(name , value);
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.carrier.WebCarrier#setParameterObject(java.lang.String, java.io.Serializable)
	 */
	public void setParameterObject(String name, Serializable valueObject) {
		// TODO Auto-generated method stub
		if (valueObject != null) {
			parametersMapping.put(name, valueObject);
		}
		else {
			logger.debug("Do not set the parameterObject is null!");
		}
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.carrier.WebCarrier#setParameterValues(java.lang.String, java.lang.String[])
	 */
	public void setParameterValues(String name, String[] values) {
		// TODO Auto-generated method stub
		parametersMapping.put(name,values);
	}

	public Set getParameterNames() {
		// TODO Auto-generated method stub
		return parametersMapping.keySet();
	}

	public Object getParameterObject(String name) {
		// TODO Auto-generated method stub
		return parametersMapping.get(name);
	}

	
	
}
